"ui";

var color = "#009688";

ui.layout(
    <drawer id="drawer">
        <vertical>
            <appbar>
                <toolbar id="toolbar" />
                
            </appbar>
            <frame w="*" h="*">
                
                <vertical>
                    <card w="*" h="80"cardCornerRadius="10" gravity="center" marginTop="10">
                        <horizontal gravity="center">
                            <Switch id="autoService" text="无障碍服务" checked="{{auto.service != null}}"  gravity="left"textSize="20sp"/>
                            <Switch id="xfc" text="    打开悬浮窗" checked="{{auto.service != null}}"  gravity="right" textSize="20sp"/>
                        </horizontal>
                    </card>
                    <vertical gravity="center">
                        <card  gravity="center" marginTop="10xp"w="auto" h="auto"cardCornerRadius="90" >
                            <vertical gravity="center" bg="#03A6EF">
                                <text text="功能选择" />
                            </vertical>
                        </card>
                    </vertical>
                    <card w="*" cardCornerRadius="10" gravity="center" marginTop="10">
                        <vertical>
                            <horizontal>
                                <text padding="10 0 0 0" text="取消点赞滑动延迟："/>
                                <input id="sjS" text="3" w="50"/>
                                <text text="至"/>
                                <input id="sjE" text="4" w="50"/>
                                <text text="秒"/>
                            </horizontal>
                            <horizontal>
                                <text padding="10 0 0 0" text="取消点赞每单延迟："/>
                                <input id="mdyc" text="3" w="50"/>
                                <text text="秒"/>
                            </horizontal>
                     <horizontal>
                                <text padding="10 0 0 0" text="总共取消"/>
                            {/*     <input id="num" text="10" w="50"/> */}
                                <text text="次数:"/>
                                <input id="yc" text="60" w="50"/>
                                <text text="次"/>
                            </horizontal> 
                             
                        </vertical>
                    </card>
                    
                    
                    
                    <list id="todoList">
                        <card w="*" h="70" margin="10 5" cardCornerRadius="2dp"
                        cardElevation="1dp" foreground="?selectableItemBackground">
                        <horizontal gravity="center_vertical">
                            <View bg="{{this.color}}" h="*" w="10" />
                            <vertical padding="10 8" h="auto" w="0" layout_weight="1">
                                <text id="title" text="{{this.title}}" textColor="#222222" textSize="16sp" maxLines="1" />
                                <text text="{{this.summary}}" textColor="#999999" textSize="14sp" maxLines="1" />
                            </vertical>
                            <View bg="{{this.color}}" h="*" w="10" />
                        </horizontal>
                        
                    </card>
                </list>
                
                
            </vertical>
            
        </frame>
    </vertical>
    <vertical layout_gravity="left" bg="#ffffff" w="280">
        <img w="280" h="200" scaleType="fitXY" src="http://images.shejidaren.com/wp-content/uploads/2014/10/023746fki.jpg"/>
        <list id="menu">
            <horizontal bg="?selectableItemBackground" w="*">
                <img w="50" h="50" padding="16" src="{{this.icon}}" tint="{{color}}"/>
                <text textColor="black" textSize="15sp" text="{{this.title}}" layout_gravity="center"/>
            </horizontal>
        </list>
    </vertical>
    </drawer>
);
alert("关于", "定制脚本加九黎q1906507927");
           
var s = storages.create("bixinzhushou")
//创建选项菜单(右上角)
ui.emitter.on("create_options_menu", menu => {
    menu.add("日志");
    menu.add("关于");
});
//监听选项菜单点击
ui.emitter.on("options_item_selected", (e, item) => {
    switch (item.getTitle()) {
        case "日志":
            app.startActivity("console");
            break;
        case "关于":
            alert("关于", "定制脚本q1906507927");
            break;
    }
    e.consumed = true;
});
activity.setSupportActionBar(ui.toolbar);
ui.menu.on("item_click", item => {
    switch (item.title) {
        case "退出":
            ui.finish();
            break;
    }
})
//两次才能返回
threads.start(function() {
    var isCanFinish = false;
    var isCanFinishTimeout;
    ui.emitter.on("back_pressed", e => {
        if (!isCanFinish) {
            isCanFinish = true;
            isCanFinishTimeout = setTimeout(() => {
                toastLog("再返回一次就失去我了哟！😁😁");
                isCanFinish = false;
            }, 500);
            e.consumed = true;
        } else {
            clearTimeout(isCanFinishTimeout);
            e.consumed = false;
        };
    });
    setInterval(() => {}, 1000)
});

if(String(s.get("sjE"))!="undefined"){
    ui.sjE.setText(String(s.get("sjE")));
    
    }

if(String(s.get("sjS"))!="undefined"){
    ui.sjS.setText(String(s.get("sjS")));
    
    }

if(String(s.get("mdyc"))!="undefined"){
    ui.mdyc.setText(String(s.get("mdyc")));
    
    }
    
    
/* if(String(s.get("num"))!="undefined"){
    ui.num.setText(String(s.get("num")));
    
    }
         */
if(String(s.get("yc"))!="undefined"){
    ui.yc.setText(String(s.get("yc")));
    
    }


ui.autoService.click(function() {
    // 用户勾选无障碍服务的选项时，跳转到页面让用户去开启
    app.startActivity({
        action: "android.settings.ACCESSIBILITY_SETTINGS"
    });

});



// 当用户回到本界面时，resume事件会被触发
ui.emitter.on("resume", function() {
    // 此时根据无障碍服务的开启情况，同步开关的状态
    ui.autoService.checked = auto.service != null;
    
});

ui.xfc.click(function() {
    app.startActivity({
    packageName: "com.android.settings",
    className: "com.android.settings.Settings$AppDrawOverlaySettingsActivity",
    data: "package:" + currentPackage()
});
});
var materialColors = ["#e91e63", "#ab47bc", "#5c6bc0", "#7e57c2", "##2196f3", "#00bcd4",
    "#26a69a", "#4caf50", "#8bc34a", "#ffeb3b", "#ffa726", "#78909c", "#8d6e63"
];

var storage = storages.create("todoList");
storage.clear()
var todoList = storage.get("items", [{
        title: "                                 开始",
        summary: "",
        color: "#f44336",
        

    },


]);
ui.todoList.setDataSource(todoList);

ui.todoList.on("item_click", function(item) {
s.put("sjE",String(ui.sjE.text()));
s.put("sjS",String(ui.sjS.text()));
s.put("mdyc",String(ui.mdyc.text()));
 //s.put("num",String(ui.num.text()));
s.put("yc",String(ui.yc.text())); 
function main() {


/* threads.start(function () {
//    var beginBtn;
//       if (beginBtn = classNameContains("Button").textContains("立即开始").findOne(2000)) {
//           beginBtn.click();
//       }
  });
        
if(!requestScreenCapture()){
    toast("请求截图失败");
    exit();
} */
console.show()
// 滑动延时
var sjys1=ui.sjS.getText()
var sjys2=ui.sjE.getText()
//取消点赞延时
var sjys3=ui.mdyc.getText()
//取消次数
var qxcs=ui.yc.getText()
toastLog("延时"+sjys3+"取消次数"+qxcs+"次")
auto.waitFor()
setScreenMetrics(1080, 2408);
log(device.width)
log(device.height)
toast("请主动切换到抖音我喜欢列表界面")
sleep(500)

//var 红心 = images.read("./红心.jpg");

for (var i = 0; i < qxcs; i++) {

向上曲线滑动()
log("已经运行"+i+"次")
}

function 向上曲线滑动() {
    x = device.width / 2 + random(-100, 50);
    y = device.height * 0.7 + random(10, 50);;
    t1 = device.height / 220
    var points = [random(600, 1200)];
    x1 = x + t1;
    y1 = y - t1;
    for (var i = 250; i > 0; i--) {
        var arr = ["0.005", "0.003", "0.004", "-0.001"]
        var item = arr[Math.floor(Math.random() * arr.length)];
        x1 = x1 + t1 * i / 3 * item;
        y1 = y1 - t1 * 0.5;
        points.push([x1, y1])
    }
    gesture.apply(null, points);//通用滑动 ,向上
var cccc=random(sjys1,sjys2)
sleep(cccc*1000)
click(966,1426);
sleep(sjys3);

}//曲线划屏向上



}
function 等待打开首页() {
    while (true) {
        if (text("首页").exists() || text("我").exists() || text("消息").exists() ||text("推荐").exists()) {
            toastLog("抖音首页=已打开")
           
            //1234定义搜索范围
          
            break;
        }
        sleep(1000)
    }
}
threads.start(function () {
    launch("com.ss.android.ugc.aweme");
    toastLog("如果自动打开抖音失败,请手动打开一下")
    等待打开首页()
main()

});
   // engines.execScriptFile("./比心语音悬浮窗1.js");
});